home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-08-18 | 30.0 KB | 1,121 lines |
- head 0.13;
- access;
- symbols;
- locks; strict;
- comment @ * @;
-
-
- 0.13
- date 92.08.18.04.46.58; author dglattin; state Exp;
- branches;
- next 0.12;
-
- 0.12
- date 92.04.13.11.43.08; author dennisg; state Exp;
- branches;
- next 0.11;
-
- 0.11
- date 92.01.03.02.55.03; author dennisg; state Exp;
- branches;
- next 0.10;
-
- 0.10
- date 91.12.10.12.05.28; author dennisg; state Exp;
- branches;
- next 0.9;
-
- 0.9
- date 91.12.03.02.01.23; author dennisg; state Exp;
- branches;
- next 0.8;
-
- 0.8
- date 91.11.24.01.20.02; author dennisg; state Exp;
- branches;
- next 0.7;
-
- 0.7
- date 91.11.23.22.18.29; author dennisg; state Exp;
- branches;
- next 0.6;
-
- 0.6
- date 91.11.21.22.27.06; author dennisg; state Exp;
- branches;
- next 0.5;
-
- 0.5
- date 91.11.20.23.29.20; author dennisg; state Exp;
- branches;
- next 0.4;
-
- 0.4
- date 91.11.19.12.34.41; author dennisg; state Exp;
- branches;
- next 0.3;
-
- 0.3
- date 91.11.07.23.23.40; author dennisg; state Exp;
- branches;
- next 0.2;
-
- 0.2
- date 91.11.07.22.30.54; author dennisg; state Exp;
- branches;
- next 0.1;
-
- 0.1
- date 91.10.24.00.45.39; author dennisg; state Exp;
- branches;
- next ;
-
-
- desc
- @This file contains the implementation of the hash table routines.
- @
-
-
- 0.13
- log
- @Saving a working version before release.
- @
- text
- @/* -*-c-*- */
-
- /* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
-
- This file is part of GNU CC.
-
- GNU CC is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- GNU CC is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNU CC; see the file COPYING. If not, write to
- the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
-
- /* As a special exception, if you link this library with files
- compiled with GCC to produce an executable, this does not cause
- the resulting executable to be covered by the GNU General Public License.
- This exception does not however invalidate any other reasons why
- the executable file might be covered by the GNU General Public License. */
-
- /*
- $Header: /usr/user/dennis_glatting/ObjC/c-runtime/dispatch.common/RCS/hash.c,v 0.12 1992/04/13 11:43:08 dennisg Exp dennisg $
- $Author: dennisg $
- $Date: 1992/04/13 11:43:08 $
- $Log: hash.c,v $
- * Revision 0.12 1992/04/13 11:43:08 dennisg
- * Check in after array version of run-time works.
- * Expect more changes as hash version and other changes are made.
- *
- * Revision 0.11 1992/01/03 02:55:03 dennisg
- * modified to handle new initialization scheme.
- * fixed code structure.
- *
- * Revision 0.10 1991/12/10 12:05:28 dennisg
- * Cleaned up file format for a distribution.
- *
- * Revision 0.9 1991/12/03 02:01:23 dennisg
- * fixed assert macro.
- * added memory allocation adjustment macro for hash size allocation.
- *
- * Revision 0.8 1991/11/24 01:20:02 dennisg
- * changed shorts back to ints.
- * the efficiency gained didn't out weight the grossness of the code.
- *
- * Revision 0.7 1991/11/23 22:18:29 dennisg
- * deleted hashIndex() and moved it to hash-inline.h
- * converted hash_value_for_key () to a inline and moved it to hash-inline.h.
- *
- * Revision 0.6 1991/11/21 22:27:06 dennisg
- * changed hash value calculation.
- * func name changed from hashValue () to hashIndex(). the
- * func really calculated a index anyway.
- * changed hash func impl. essentially it was calculating a hash value
- * from a hash value. this is a implementation thing.
- *
- * Revision 0.5 1991/11/20 23:29:20 dennisg
- * converted hashIndex() to a inline.
- *
- * Revision 0.4 1991/11/19 12:34:41 dennisg
- * bug in hash_delete (). It was using void* to obtain nodes to
- * pass to hash_remove (). The value passed to hash_removed () is a
- * entry from the node structure rather than the node itself. Using
- * void* removed compiler checking.
- * Modified to implement cache expansion.
- *
- * Revision 0.3 1991/11/07 23:23:40 dennisg
- * implemented hash table expansion as suggested by rms.
- *
- * Revision 0.2 1991/11/07 22:30:54 dennisg
- * added copyleft
- *
- * Revision 0.1 1991/10/24 00:45:39 dennisg
- * Initial check in. Preliminary development stage.
- *
- */
-
-
- #include <hash.h>
- #include <objc.h>
- #include <objcP.h>
- #include <objc-protoP.h>
-
- #include <assert.h>
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
-
-
- /* These two macros determine
- when a hash table is full and
- by how much it should be
- expanded respectively.
-
- These equations are
- percentages. */
- #define FULLNESS(cache) \
- ((((cache)->sizeOfHash * 75 ) / 100) <= (cache)->entriesInHash)
- #define EXPANSION(cache) \
- ((cache)->sizeOfHash * 2 )
-
- Cache_t
- hash_new (u_int sizeOfHash, HashFunc aHashFunc, CompareFunc aCompareFunc) {
-
- Cache_t retCache;
-
-
- /* Pass me a value greater
- than 0 and a power of 2. */
- assert(sizeOfHash);
- assert( !(sizeOfHash & (sizeOfHash - 1)));
-
- /* Allocate the cache
- structure. calloc () insures
- its initialization for
- default values. */
- retCache = calloc (1, sizeof (Cache));
- assert(retCache);
-
- /* Allocate the array of
- buckets for the cache.
- calloc() initializes all of
- the pointers to NULL. */
- retCache->theNodeTable = calloc (sizeOfHash, sizeof (CacheNode_t));
- assert(retCache->theNodeTable);
-
- retCache->sizeOfHash = sizeOfHash;
-
- /* This should work for all
- processor architectures? */
- retCache->mask = ( sizeOfHash - 1 );
-
- /* Store the hashing function
- so that codes can be
- computed. */
- retCache->hashFunc = aHashFunc;
-
- /* Store the function that
- compares hash keys to
- determine if they are
- equal. */
- retCache->compareFunc = aCompareFunc;
-
- return retCache;
- }
-
-
- void
- hash_delete (Cache_t theCache) {
-
- CacheNode_t aNode;
-
-
- /* Purge all key/value pairs
- from the table. */
- while (aNode = hash_next (theCache, NULL))
- hash_remove (theCache, aNode->theKey);
-
- /* Release the array of nodes
- and the cache itself. */
- free (theCache->theNodeTable);
- free (theCache);
- }
-
-
- void
- hash_add (Cache_t* theCache, void* aKey, void* aValue) {
-
- u_int indx = (* (*theCache)->hashFunc)(*theCache, aKey);
- CacheNode_t aCacheNode = calloc (1, sizeof (CacheNode));
-
-
- assert(aCacheNode);
-
- /* Initialize the new node. */
- aCacheNode->theKey = aKey;
- aCacheNode->theValue = aValue;
- aCacheNode->nextNode = (* (*theCache)->theNodeTable)[ indx ];
-
- /* Debugging.
-
- Check the list for another
- key. */
- #ifdef DEBUG
- { CacheNode_t checkHashNode = (* (*theCache)->theNodeTable)[ indx ];
-
- while (checkHashNode) {
-
- assert(checkHashNode->theKey != aKey);
- checkHashNode = checkHashNode->nextNode;
- }
- }
- #endif
-
- /* Install the node as the
- first element on the list. */
- (* (*theCache)->theNodeTable)[ indx ] = aCacheNode;
-
- /* Bump the number of entries
- in the cache. */
- ++ (*theCache)->entriesInHash;
-
- /* Check the hash table's
- fullness. We're going
- to expand if it is above
- the fullness level. */
- if (FULLNESS (*theCache)) {
- /* The hash table has reached
- its fullness level. Time to
- expand it.
-
- I'm using a slow method
- here but is built on other
- primitive functions thereby
- increasing its
- correctness. */
- CacheNode_t aNode = NULL;
- Cache_t newCache = hash_new (EXPANSION (*theCache),
- (*theCache)->hashFunc,
- (*theCache)->compareFunc);
-
- DEBUG_PRINTF (stderr, "Expanding cache %#x from %d to %d\n",
- *theCache, (*theCache)->sizeOfHash, newCache->sizeOfHash);
-
- /* Copy the nodes from the
- first hash table to the
- new one. */
- while (aNode = hash_next (*theCache, aNode))
- hash_add (&newCache, aNode->theKey, aNode->theValue);
-
- /* Trash the old cache. */
- hash_delete (*theCache);
-
- /* Return a pointer to the new
- hash table. */
- *theCache = newCache;
- }
- }
-
-
- void
- hash_remove (Cache_t theCache, void* aKey) {
-
- u_int indx = (*theCache->hashFunc)(theCache, aKey);
- CacheNode_t aCacheNode = (*theCache->theNodeTable)[ indx ];
-
-
- /* We assume there is an entry
- in the table. Error if it
- is not. */
- assert(aCacheNode);
-
- /* Special case. First element
- is the key/value pair to be
- removed. */
- if ((*theCache->compareFunc)(aCacheNode->theKey, aKey)) {
- (*theCache->theNodeTable)[ indx ] = aCacheNode->nextNode;
- free (aCacheNode);
- } else {
- /* Otherwise, find the hash
- entry. */
- CacheNode_t prevHashNode = aCacheNode;
- BOOL removed = NO;
-
- do {
-
- if ((*theCache->compareFunc)(aCacheNode->theKey, aKey)) {
- prevHashNode->nextNode = aCacheNode->nextNode, removed = YES;
- free (aCacheNode);
- } else
- prevHashNode = aCacheNode, aCacheNode = aCacheNode->nextNode;
- } while (!removed && aCacheNode);
- assert(removed);
- }
-
- /* Decrement the number of
- entries in the hash table. */
- --theCache->entriesInHash;
- }
-
-
- CacheNode_t
- hash_next (Cache_t theCache, CacheNode_t aCacheNode) {
-
- CacheNode_t theCacheNode = aCacheNode;
-
-
- /* If the scan is being started
- then reset the last node
- visitied pointer and bucket
- index. */
- if (!theCacheNode)
- theCache->lastBucket = 0;
-
- /* If there is a node visited
- last then check for another
- entry in the same bucket;
- Otherwise step to the next
- bucket. */
- if (theCacheNode)
- if (theCacheNode->nextNode)
- /* There is a node which
- follows the last node
- returned. Step to that node
- and retun it. */
- return theCacheNode->nextNode;
- else
- ++theCache->lastBucket;
-
- /* If the list isn't exhausted
- then search the buckets for
- other nodes. */
- if (theCache->lastBucket < theCache->sizeOfHash) {
- /* Scan the remainder of the
- buckets looking for an entry
- at the head of the list.
- Return the first item
- found. */
- while (theCache->lastBucket < theCache->sizeOfHash)
- if ((*theCache->theNodeTable)[ theCache->lastBucket ])
- return (*theCache->theNodeTable)[ theCache->lastBucket ];
- else
- ++theCache->lastBucket;
-
- /* No further nodes were found
- in the hash table. */
- return NULL;
- } else
- return NULL;
- }
-
-
- /* Given key, return its
- value. Return NULL if the
- key/value pair isn't in
- the hash. */
- void*
- hash_value_for_key (Cache_t theCache, void* aKey) {
-
- CacheNode_t aCacheNode =
- (*theCache->theNodeTable)[(*theCache->hashFunc)(theCache, aKey)];
- void* retVal = NULL;
-
-
- if (aCacheNode)
- do {
- if ((*theCache->compareFunc)(aCacheNode->theKey, aKey))
- retVal = aCacheNode->theValue;
- else
- aCacheNode = aCacheNode->nextNode;
- } while (!retVal && aCacheNode);
-
- return retVal;
- }
- @
-
-
- 0.12
- log
- @Check in after array version of run-time works.
- Expect more changes as hash version and other changes are made.
- @
- text
- @d1 28
- a28 19
- /* -*-c-*-
- * This file contains the hashing implementation.
- *
- * Copyright (C) 1991 Threaded Technologies Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 1, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should receive a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- $Header: /usr/user/dennis_glatting/ObjC/c-runtime/hash/RCS/hash.c,v 0.11 1992/01/03 02:55:03 dennisg Exp dennisg $
- d30 1
- a30 1
- $Date: 1992/01/03 02:55:03 $
- d32 4
- @
-
-
- 0.11
- log
- @modified to handle new initialization scheme.
- fixed code structure.
- @
- text
- @d19 1
- a19 1
- $Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash.c,v 0.10 1991/12/10 12:05:28 dennisg Exp dennisg $
- d21 1
- a21 1
- $Date: 1991/12/10 12:05:28 $
- d23 4
- d72 3
- a74 3
- #include <hash-inline.h>
- #include <ObjC.h>
- #include <ObjC-private.h>
- d92 1
- a92 1
- (((cache)->sizeOfHash * 175 ) / 100 )
- d94 2
- a95 2
- #define MEMORY_ALLOCATION_ADJUST(i) \
- ((i&0x01)?i:(i-1))
- a96 2
- Cache_t hash_new (u_int sizeOfHash) {
-
- d100 2
- d103 1
- a104 6
- /* Memory is allocated on this
- machine in even address
- chunks. Therefore the
- modulus must be odd. */
- sizeOfHash = MEMORY_ALLOCATION_ADJUST(sizeOfHash);
-
- d114 1
- a114 1
- calloc () initializes all of
- d121 15
- d140 2
- a141 1
- void hash_delete (Cache_t theCache) {
- d146 1
- a146 1
- /* Purge all key/value pairs
- d158 2
- a159 1
- void hash_add (Cache_t* theCache, void* aKey, void* aValue) {
- d161 1
- a161 1
- u_int indx = hashIndex(*theCache, aKey);
- d210 3
- a212 2
- Cache_t newCache =
- hash_new (MEMORY_ALLOCATION_ADJUST( EXPANSION (*theCache)));
- d233 2
- a234 1
- void hash_remove (Cache_t theCache, void* aKey) {
- d236 1
- a236 1
- u_int indx = hashIndex(theCache, aKey);
- d248 1
- a248 1
- if (aCacheNode->theKey == aKey) {
- d259 1
- a259 1
- if (aCacheNode->theKey == aKey) {
- d274 2
- a275 1
- CacheNode_t hash_next (Cache_t theCache, CacheNode_t aCacheNode) {
- d325 22
- @
-
-
- 0.10
- log
- @Cleaned up file format for a distribution.
- @
- text
- @d19 1
- a19 1
- $Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash.c,v 0.9 1991/12/03 02:01:23 dennisg Exp dennisg $
- d21 1
- a21 1
- $Date: 1991/12/03 02:01:23 $
- d23 3
- a72 1
- #include <libc.h>
- d74 3
- @
-
-
- 0.9
- log
- @fixed assert macro.
- added memory allocation adjustment macro for hash size allocation.
- @
- text
- @d19 1
- a19 1
- $Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash.c,v 0.8 1991/11/24 01:20:02 dennisg Exp dennisg $
- d21 1
- a21 1
- $Date: 1991/11/24 01:20:02 $
- d23 4
- d65 1
- a65 1
- #include <hash-inline.h>
- d67 1
- a67 1
- #include <ObjC-private.h>
- d73 11
- a83 11
- /* These two macros determine
- when a hash table is full and
- by how much it should be
- expanded respectively.
-
- These equations are
- percentages. */
- #define FULLNESS(cache) \
- ((((cache)->sizeOfHash * 75 ) / 100) <= (cache)->entriesInHash)
- #define EXPANSION(cache) \
- (((cache)->sizeOfHash * 175 ) / 100 )
- d85 2
- a86 2
- #define MEMORY_ALLOCATION_ADJUST(i) \
- ((i&0x01)?i:(i-1))
- d91 1
- a91 1
-
- d94 6
- a99 6
-
- /* Memory is allocated on this
- machine in even address
- chunks. Therefore the
- modulus must be odd. */
- sizeOfHash = MEMORY_ALLOCATION_ADJUST(sizeOfHash);
- d115 1
- a115 1
- retCache->sizeOfHash = sizeOfHash;
- d170 21
- a190 21
- /* Bump the number of entries
- in the cache. */
- ++ (*theCache)->entriesInHash;
-
- /* Check the hash table's
- fullness. We're going
- to expand if it is above
- the fullness level. */
- if (FULLNESS (*theCache)) {
- /* The hash table has reached
- its fullness level. Time to
- expand it.
-
- I'm using a slow method
- here but is built on other
- primitive functions thereby
- increasing its
- correctness. */
- CacheNode_t aNode = NULL;
- Cache_t newCache =
- hash_new (MEMORY_ALLOCATION_ADJUST( EXPANSION (*theCache)));
- d192 8
- a199 8
- DEBUG_PRINTF (stderr, "Expanding cache %#x from %d to %d\n",
- *theCache, (*theCache)->sizeOfHash, newCache->sizeOfHash);
-
- /* Copy the nodes from the
- first hash table to the
- new one. */
- while (aNode = hash_next (*theCache, aNode))
- hash_add (&newCache, aNode->theKey, aNode->theValue);
- d201 7
- a207 7
- /* Trash the old cache. */
- hash_delete (*theCache);
-
- /* Return a pointer to the new
- hash table. */
- *theCache = newCache;
- }
- d244 4
- a247 4
-
- /* Decrement the number of
- entries in the hash table. */
- --theCache->entriesInHash;
- @
-
-
- 0.8
- log
- @changed shorts back to ints.
- the efficiency gained didn't out weight the grossness of the code.
- @
- text
- @d19 1
- a19 1
- $Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash.c,v 0.7 1991/11/23 22:18:29 dennisg Exp dennisg $
- d21 1
- a21 1
- $Date: 1991/11/23 22:18:29 $
- d23 4
- d29 1
- a29 1
- * converted hash_value_for_key() to a inline and moved it to hash-inline.h.
- d33 1
- a33 1
- * func name changed from hashValue() to hashIndex(). the
- d42 2
- a43 2
- * bug in hash_delete(). It was using void* to obtain nodes to
- * pass to hash_remove(). The value passed to hash_removed() is a
- d77 1
- a77 1
- ((((cache)->sizeOfHash * 75 ) / 100 ) <= (cache)->entriesInHash)
- d81 2
- d84 1
- a84 1
- Cache_t hash_new( u_int sizeOfHash ) {
- d87 1
- d89 7
- a96 2
- assert( sizeOfHash );
-
- d98 1
- a98 1
- structure. calloc() insures
- d101 2
- a102 2
- retCache = calloc( 1, sizeof( Cache ));
- assert( retCache );
- d106 1
- a106 1
- calloc() initializes all of
- d108 2
- a109 2
- retCache->theNodeTable = calloc( sizeOfHash, sizeof( CacheNode_t ));
- assert( retCache->theNodeTable );
- d111 1
- a111 1
- retCache->sizeOfHash = sizeOfHash;
- d117 1
- a117 1
- void hash_delete( Cache_t theCache ) {
- d124 2
- a125 2
- while( aNode = hash_next( theCache, NULL ))
- hash_remove( theCache, aNode->theKey );
- d129 2
- a130 2
- free( theCache->theNodeTable );
- free( theCache );
- d134 1
- a134 1
- void hash_add( Cache_t* theCache, void* aKey, void* aValue ) {
- d136 2
- a137 2
- u_int indx = hashIndex( *theCache, aKey );
- CacheNode_t aCacheNode = calloc( 1, sizeof( CacheNode ));
- d140 1
- a140 1
- assert( aCacheNode );
- d145 1
- a145 1
- aCacheNode->nextNode = ( *( *theCache )->theNodeTable )[ indx ];
- d152 1
- a152 1
- { CacheNode_t checkHashNode = ( *( *theCache )->theNodeTable )[ indx ];
- d154 1
- a154 1
- while( checkHashNode ) {
- d156 1
- a156 1
- assert( checkHashNode->theKey != aKey );
- d164 1
- a164 1
- ( *( *theCache )->theNodeTable )[ indx ] = aCacheNode;
- d168 1
- a168 1
- ++( *theCache )->entriesInHash;
- d174 1
- a174 1
- if(FULLNESS( *theCache )) {
- a183 1
- Cache_t newCache = hash_new(EXPANSION( *theCache ));
- d185 2
- d189 1
- a189 1
- *theCache, ( *theCache )->sizeOfHash, newCache->sizeOfHash);
- d194 2
- a195 2
- while( aNode = hash_next( *theCache, aNode ))
- hash_add( &newCache, aNode->theKey, aNode->theValue );
- d198 1
- a198 1
- hash_delete( *theCache );
- d207 1
- a207 1
- void hash_remove( Cache_t theCache, void* aKey ) {
- d209 2
- a210 2
- u_int indx = hashIndex( theCache, aKey );
- CacheNode_t aCacheNode = ( *theCache->theNodeTable )[ indx ];
- d216 1
- a216 1
- assert( aCacheNode );
- d221 3
- a223 3
- if( aCacheNode->theKey == aKey ) {
- ( *theCache->theNodeTable )[ indx ] = aCacheNode->nextNode;
- free( aCacheNode );
- d232 1
- a232 1
- if( aCacheNode->theKey == aKey ) {
- d234 1
- a234 1
- free( aCacheNode );
- d237 2
- a238 2
- } while( !removed && aCacheNode );
- assert( removed );
- d247 1
- a247 1
- CacheNode_t hash_next( Cache_t theCache, CacheNode_t aCacheNode ) {
- d256 1
- a256 1
- if( !theCacheNode )
- d264 2
- a265 2
- if( theCacheNode )
- if( theCacheNode->nextNode )
- d277 1
- a277 1
- if( theCache->lastBucket < theCache->sizeOfHash ) {
- d283 3
- a285 3
- while( theCache->lastBucket < theCache->sizeOfHash )
- if(( *theCache->theNodeTable )[ theCache->lastBucket ])
- return ( *theCache->theNodeTable )[ theCache->lastBucket ];
- @
-
-
- 0.7
- log
- @deleted hashIndex() and moved it to hash-inline.h
- converted hash_value_for_key() to a inline and moved it to hash-inline.h.
- @
- text
- @d19 1
- a19 1
- $Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash.c,v 0.6 1991/11/21 22:27:06 dennisg Exp dennisg $
- d21 1
- a21 1
- $Date: 1991/11/21 22:27:06 $
- d23 4
- d124 1
- a124 1
- u_short indx = hashIndex( *theCache, aKey );
- d196 1
- a196 1
- u_short indx = hashIndex( theCache, aKey );
- @
-
-
- 0.6
- log
- @changed hash value calculation.
- func name changed from hashValue() to hashIndex(). the
- func really calculated a index anyway.
- changed hash func impl. essentually it was calculating a hash value
- from a hash value. this is a implementation thing.
- @
- text
- @d19 1
- a19 1
- $Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash.c,v 0.5 1991/11/20 23:29:20 dennisg Exp dennisg $
- d21 1
- a21 1
- $Date: 1991/11/20 23:29:20 $
- d23 7
- d53 1
- a73 9
- static inline u_int hashIndex( Cache_t theCache, void* aKey ) {
-
-
- assert (sizeof (u_int) == sizeof (void*));
-
- return ((u_int)aKey) % theCache->sizeOfHash ;
- }
-
-
- d120 1
- a120 1
- u_int indx = hashIndex( *theCache, aKey );
- d192 1
- a192 1
- u_int indx = hashIndex( theCache, aKey );
- a226 22
- }
-
-
- void* hash_value_for_key( Cache_t theCache, void* aKey ) {
-
- u_int indx = hashIndex( theCache, aKey );
- CacheNode_t aCacheNode = ( *theCache->theNodeTable )[ indx ];
- void* retVal = NULL;
-
-
- if( aCacheNode ) {
- BOOL found = NO;
-
- do {
- if( aCacheNode->theKey == aKey )
- retVal = aCacheNode->theValue, found = YES;
- else
- aCacheNode = aCacheNode->nextNode;
- } while( !found && aCacheNode );
- }
-
- return retVal;
- @
-
-
- 0.5
- log
- @converted hashValue() to a inline.
- @
- text
- @d19 1
- a19 1
- $Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash.c,v 0.4 1991/11/19 12:34:41 dennisg Exp dennisg $
- d21 1
- a21 1
- $Date: 1991/11/19 12:34:41 $
- d23 3
- d66 1
- a66 1
- static inline u_int hashValue( Cache_t theCache, void* aKey ) {
- a67 7
- u_int hash = 0;
- int i;
-
-
- assert( theCache->numberOfMaskBits );
- for( i = 0; i < ( sizeof( aKey ) * 8 ); i += theCache->numberOfMaskBits )
- hash ^= (( u_int )aKey ) >> i ;
- d69 3
- a71 1
- return ( hash & theCache->mask ) % theCache->sizeOfHash;
- a77 1
- int i;
- a97 14
- /* Calculate the number of
- bits required to represent
- the hash mask. */
- retCache->numberOfMaskBits =
- ceil( log( retCache->sizeOfHash ) / log( 2 ));
-
- /* Form a bit mask for the
- hash. */
- for( i = 0; i < retCache->numberOfMaskBits; ++i )
- retCache->mask = ( retCache->mask << 1 ) | 0x01 ;
-
- assert( retCache->numberOfMaskBits );
- assert( retCache->mask );
-
- d121 1
- a121 1
- u_int indx = hashValue( *theCache, aKey );
- d193 1
- a193 1
- u_int indx = hashValue( theCache, aKey );
- d233 1
- a233 1
- u_int indx = hashValue( theCache, aKey );
- @
-
-
- 0.4
- log
- @bug in hash_delete(). It was using void* to obtain nodes to
- pass to hash_remove(). The value passed to hash_removed() is a
- entry from the node structure rather than the node itself. Using
- void* removed compiler checking.
- Modified to implement cache expansion.
- @
- text
- @d19 1
- a19 1
- $Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash.c,v 0.3 1991/11/07 23:23:40 dennisg Exp dennisg $
- d21 1
- a21 1
- $Date: 1991/11/07 23:23:40 $
- d23 7
- a61 2
- /* Local forward decl. */
- u_int hashValue( Cache_t, void* );
- d63 1
- d65 12
- a318 13
-
- u_int hashValue( Cache_t theCache, void* aKey ) {
-
- u_int hash = 0;
- int i;
-
-
- assert( theCache->numberOfMaskBits );
- for( i = 0; i < ( sizeof( aKey ) * 8 ); i += theCache->numberOfMaskBits )
- hash ^= (( u_int )aKey ) >> i ;
-
- return ( hash & theCache->mask ) % theCache->sizeOfHash;
- }
- @
-
-
- 0.3
- log
- @implemented hash table expansion as suggested by rms.
- @
- text
- @d19 1
- a19 1
- $Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash.c,v 0.2 1991/11/07 22:30:54 dennisg Exp dennisg $
- d21 1
- a21 1
- $Date: 1991/11/07 22:30:54 $
- d23 3
- d37 1
- d50 4
- a53 2
- #define FULLNESS ( 100 / 75 )
- #define EXPANSION ( 135 / 100 )
- d103 1
- a103 1
- void* aNode;
- d109 1
- a109 1
- hash_remove( theCache, aNode );
- d129 1
- a129 1
- aCacheNode->nextNode = ( *( **theCache ).theNodeTable )[ indx ];
- d136 1
- a136 1
- { CacheNode_t checkHashNode = ( *( **theCache ).theNodeTable )[ indx ];
- d148 1
- a148 1
- ( *( **theCache ).theNodeTable )[ indx ] = aCacheNode;
- d152 1
- a152 1
- ++( **theCache ).entriesInHash;
- d158 1
- a158 1
- if(( **theCache ).entriesInHash * FULLNESS ) {
- d168 1
- a168 1
- Cache_t newCache = hash_new(( **theCache ).sizeOfHash * EXPANSION );
- d170 4
- a173 1
-
- @
-
-
- 0.2
- log
- @added copyleft
- @
- text
- @d19 1
- a19 1
- $Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/hash.c,v 0.1 1991/10/24 00:45:39 dennisg Exp dennisg $
- d21 1
- a21 1
- $Date: 1991/10/24 00:45:39 $
- d23 3
- d39 9
- d53 1
- a53 1
- Cache_t hash_new( u_int numberOfBuckets ) {
- d59 1
- a59 1
- assert( numberOfBuckets );
- d72 1
- a72 1
- retCache->theNodeTable = calloc( numberOfBuckets, sizeof( CacheNode_t ));
- d75 1
- a75 1
- retCache->numberOfBuckets = numberOfBuckets;
- d81 1
- a81 1
- ceil( log( retCache->numberOfBuckets ) / log( 2 ));
- d112 1
- a112 1
- void hash_add( Cache_t theCache, void* aKey, void* aValue ) {
- d114 1
- a114 1
- u_int indx = hashValue( theCache, aKey );
- d123 1
- a123 1
- aCacheNode->nextNode = ( *theCache->theNodeTable )[ indx ];
- d130 1
- a130 1
- { CacheNode_t checkHashNode = ( *theCache->theNodeTable )[ indx ];
- d138 1
- d142 1
- a142 1
- ( *theCache->theNodeTable )[ indx ] = aCacheNode;
- d144 34
- a177 1
- #endif
- d214 4
- d273 1
- a273 1
- if( theCache->lastBucket < theCache->numberOfBuckets ) {
- d279 1
- a279 1
- while( theCache->lastBucket < theCache->numberOfBuckets )
- d303 1
- a303 1
- return ( hash & theCache->mask ) % theCache->numberOfBuckets;
- @
-
-
- 0.1
- log
- @Initial check in. Preliminary development stage.
- @
- text
- @d4 22
- a25 4
- $Header$
- $Author$
- $Date$
- $Log$
- @
-